package com.pj.gen;


import cn.hutool.core.io.FileUtil;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class Print {
    //荧色
    public static void print(Object object) {

        System.out.print("\033[" + 0 + ";9" + 6 + ";0m" + LocalDateTime.now() + " :   " + "\033[0m");
        System.out.println("\033[" + 0 + ";9" + 6 + ";0m" + object.toString() + "\033[0m");
    }

    //橙色
    public static void printC(Object object) {
        System.out.println("\033[" + 0 + ";9" + 1 + ";4m" + object.toString() + "\033[0m");
    }

    //绿色
    public static void printG(Object object) {
        System.out.println("\033[" + 0 + ";9" + 2 + ";4m" + object.toString() + "\033[0m");
    }

    //黄色
    public static void printY(Object object) {
        System.out.println("\033[" + 0 + ";9" + 3 + ";4m" + object.toString() + "\033[0m");
    }

    //蓝色
    public static void printB(Object object) {
        System.out.println("\033[" + 0 + ";9" + 4 + ";4m" + object.toString() + "\033[0m");
    }

    //红色
    public static void printR(Object object) {
        System.out.println("\033[" + 0 + ";9" + 5 + ";4m" + object.toString() + "\033[0m");
    }

    public static void main(String[] args) throws FileNotFoundException {
        File file = ResourceUtils.getFile(System.getProperty("user.dir") + "\\pom.xml");
        List<String> strings = FileUtil.readLines(file, Charset.forName("utf-8"));
        Optional<String> groupId = strings.stream().filter(x -> x.contains("<groupId>")).findFirst();
        Optional<String> artifactId = strings.stream().filter(x -> x.contains("<artifactId>")).findFirst();
        //工作目录
        System.out.println(System.getProperty("user.dir"));
        //组
        System.out.println(groupId.get());
        //项目名称
        System.out.println(artifactId.get());
    }
}